package com.swz.dcrm.adpter;

import android.content.Context;
import android.widget.TextView;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.Boutique;

import java.text.DecimalFormat;
import java.util.List;

public class BoutiqueDetailAdapter extends CustomAdapter<Boutique>{


    public BoutiqueDetailAdapter(Context context, List<Boutique> datas) {
        super(context, R.layout.item_boutique_detail, datas);
    }

    @Override
    protected void convert(ViewHolder holder, Boutique boutique, int position) {
        holder.setText(R.id.tv_boutique_name, boutique.getBoutiqueName());
        TextView price=holder.getView(R.id.tv_price);
        price.setText(formatTosepara(Double.parseDouble(boutique.getPrice())));
        holder.setOnClickListener(R.id.iv_remove, v -> {

            getDatas().remove(position);
            notifyItemRemoved(position);
            notifyItemRangeChanged(position,mDatas.size()-position);
            if(onClickListener!=null){
                onClickListener.onItemClick(boutique);
            }
        });
    }

    public String getTotal(){
        if(mDatas.size()==0){
            return "";
        }
        double d=0;
        for(Boutique boutique:mDatas){
            if(boutique.getPrice()==null){
                continue;
            }
            d+=Double.valueOf(boutique.getPrice());
        }
        return formatTosepara(d);
    }
    public static String formatTosepara(double data) {
        DecimalFormat df = new DecimalFormat("#,###.00");
        return df.format(data);
    }
}
